﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace November {
    class Utility {
        public static readonly String[] IMAGE_EXTENSIONS = {
            ".bmp", 
            ".gif", 
            ".jpg", 
            ".jpeg", 
            ".png"
        };

        public static Boolean ImageFilter(String fileName) {
            return IMAGE_EXTENSIONS.Any(fileName.ToLower().EndsWith);
        }

        public static Int32 FindEarlier<T>(IIndexed<T> list, Int32 index) {
            if (index == 0) return index;

            T current = list[index -= 1];
            while (index > 0) {
                if (!list[index -= 1].Equals(current)) {
                    return index + 1;
                }
            }

            return 0;
        }

        public static Int32 FindLater<T>(IIndexed<T> list, Int32 index) {
            if (index == list.Count - 1) return index;

            T current = list[index];
            while (index < list.Count - 1) {
                if (!list[index += 1].Equals(current)) {
                    return index;
                }
            }

            return list.Count - 1;
        }
    }
}
